package com.hpxx.ylzswl.activity;

import android.content.Intent;
import android.graphics.Color;
import android.net.Uri;
import android.os.Bundle;
import android.text.InputFilter;
import android.text.Spanned;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.widget.EditText;
import android.widget.HorizontalScrollView;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.alibaba.fastjson.JSON;
import com.hpxx.ylzswl.R;
import com.hpxx.ylzswl.base.BaseActivity;
import com.hpxx.ylzswl.base.BaseEvent;
import com.hpxx.ylzswl.bean.OrderItemBean;
import com.hpxx.ylzswl.dialog.BaseDialog;
import com.hpxx.ylzswl.dialog.ComfirmOrderDialog;
import com.hpxx.ylzswl.dialog.ErWeiMaDialog;
import com.hpxx.ylzswl.event.NoticeEvent;
import com.hpxx.ylzswl.event.OrderIdEvent;
import com.hpxx.ylzswl.event.OrderListEvent;
import com.hpxx.ylzswl.event.OrderTabListEvent;
import com.hpxx.ylzswl.https.HttpAddress;
import com.hpxx.ylzswl.https.RequestParams;
import com.hpxx.ylzswl.info.ManageOrderDetailInfo;
import com.hpxx.ylzswl.utils.ConstantsUtils;
import com.hpxx.ylzswl.utils.ViewHolder;
import com.hpxx.ylzswl.views.NoScrollingListView;
import com.hpxx.ylzswl.views.RoundImageView;
import com.universal.frame.generalutils.GeneralUtil;
import com.universal.frame.generalutils.JsonUtil;
import com.universal.frame.generalutils.SharedPreferencesUtil;
import com.universal.frame.generalutils.ToastUtil;
import com.universal.frame.okhttp.OKHttpUtils;
import com.universal.frame.okhttp.ResultCallBack;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import de.greenrobot.event.EventBus;
import de.greenrobot.event.Subscribe;
import okhttp3.Request;

import static com.activeandroid.Cache.getContext;

/**
 * Created by Administrator on 2017/11/8.
 */

public class OrderDetailsAvtivity extends BaseActivity implements
        View.OnClickListener,ResultCallBack {

    private LinearLayout ll_jcxm, ll_add_ims;
    private RoundImageView iv_ys_img;
    private NoScrollingListView nlv_comm;

    private TextView tv_btn, tv_kf;
    private ComfirmOrderDialog comfirmOrderDialog;
    private ErWeiMaDialog erWeiMaDialog;
    private TextView tv_state;
    private String orderId;
    private String noticeId;
    private ManageOrderDetailInfo info = new ManageOrderDetailInfo();
    private ArrayList<String> list = new ArrayList<String>();
    public List<OrderItemBean> itemList = new ArrayList<OrderItemBean>();
    public TextView tv_item;
    private TextView tvHzName;
    private TextView tvHzBednum;
    private TextView tvHzPhone;
    private TextView tvHzBloodnum;
    private TextView tvHzTime;
//医生
    private TextView tvYsXinxi;
    private TextView tvYsHos;
//物流
    private TextView tvLogisticXinxi;
    private TextView tvLogisticBeizhu;
    private TextView tvLogisticTime;
//销售
    private TextView tvSaleName;
    private TextView tvSalePhone;
    private TextView tvSaleNum;
    private TextView tvSaleTpye;
    private TextView tvSaleRe;
    private TextView tvSaleTime;

   private ImageView iv_call;
    private String kfPhone;
    private TextView tv_itemIMG;
    private HorizontalScrollView hsv_img;
    private String ewm;
    private ImageView iv_patphone;
    private ImageView iv_salephone,iv_ys_call;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_order_details);
        back();
        setTitle("订单详情");
    }
    //订单详情
    private void orderDetailPost(String orderId){
        OKHttpUtils.postAsync(this
                , HttpAddress.ORDER_Detail_URL
                , new RequestParams(this).getOrderDetailParams(3,orderId), this
                ,true,1);
    }
    //消息中心红点消失
    private void NoticeReadPost(String noticeId){
        OKHttpUtils.postAsync(this
                , HttpAddress.NOTICE_UPDATARED_URL
                , new RequestParams(this).getMessageUpdataParams(noticeId), this
                ,false,2);
    }
    //待接单接单接口
    private void receivePost(String orderId,String orderNote){
        OKHttpUtils.postAsync(this
                , HttpAddress.ORDER_RECEIVE_URL
                , new RequestParams(this).getReceiveOrderParams(orderId,orderNote), this
                ,false,3);
    }
    @Override
    public void initView() {
        orderId =  getIntent().getStringExtra("ORDER_ID");
        noticeId = getIntent().getStringExtra("NOTICE_ID");
        if (noticeId != null){
            NoticeReadPost(noticeId);
        }
        kfPhone= SharedPreferencesUtil.getString(getApplication(), ConstantsUtils.USER_SERVERTEL);
        tv_state = (TextView) findViewById(R.id.tv_state);
        tv_itemIMG = (TextView) findViewById(R.id.tv_itemIMG);
        hsv_img = (HorizontalScrollView) findViewById(R.id.hsv_img);
        ll_jcxm = (LinearLayout) findViewById(R.id.ll_jcxm); //检测项目
        iv_ys_img = (RoundImageView) findViewById(R.id.iv_ys_img);
        ll_add_ims = (LinearLayout) findViewById(R.id.ll_add_ims);
        tv_item = (TextView) findViewById(R.id.tv_item);
        tv_btn = (TextView) findViewById(R.id.tv_btn);
        tv_kf = (TextView) findViewById(R.id.tv_kf);
        tvHzName = (TextView) findViewById(R.id.tv_hz_name);
        tvHzBednum = (TextView) findViewById(R.id.tv_hz_bednum);
        tvHzPhone = (TextView) findViewById(R.id.tv_hz_phone);
        tvHzBloodnum = (TextView) findViewById(R.id.tv_hz_bloodnum);
        tvHzTime = (TextView) findViewById(R.id.tv_hz_time);
        tvYsXinxi = (TextView) findViewById(R.id.tv_ys_xinxi);
        tvYsHos = (TextView) findViewById(R.id.tv_ys_hos);
        tvLogisticXinxi = (TextView) findViewById(R.id.tv_logistic_xinxi);
        tvLogisticBeizhu = (TextView) findViewById(R.id.tv_logistic_beizhu);
        tvLogisticTime = (TextView) findViewById(R.id.tv_logistic_time);
        tvSaleName = (TextView) findViewById(R.id.tv_sale_name);
        tvSalePhone = (TextView) findViewById(R.id.tv_sale_phone);
        tvSaleNum = (TextView) findViewById(R.id.tv_sale_num);
        tvSaleTpye = (TextView) findViewById(R.id.tv_sale_tpye);
        tvSaleRe = (TextView) findViewById(R.id.tv_sale_re);
        tvSaleTime = (TextView) findViewById(R.id.tv_sale_time);
        iv_call = (ImageView) findViewById(R.id.iv_call);
        //患者电话
        iv_patphone = (ImageView) findViewById(R.id.iv_patphone);
        iv_salephone =  (ImageView) findViewById(R.id.iv_salephone);
        iv_ys_call = (ImageView) findViewById(R.id.iv_ys_call);
        orderDetailPost(orderId);
    }

    private void intview(String status) {
        if ("0".equals(status)) {
            tv_state.setText("待接单");
            tv_btn.setText("立即接单");
            tv_btn.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    ComfirmDialog();
                }
            });
            tv_kf.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Intent intentCallPhone = new Intent(Intent.ACTION_DIAL, Uri.parse("tel:" + kfPhone));
                    startActivity(intentCallPhone);
                }
            });
        } else if ("1".equals(status)) {
            tv_state.setText("已接单");
            tv_btn.setText("录入患者信息");
            tv_btn.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Intent  intent =  new Intent(OrderDetailsAvtivity.this,EditPatientActivity.class);
                    intent.putExtra("patientName",info.orderDetail.patientName);
                    intent.putExtra("ORDER_ID",info.orderDetail.orderId);
                    intent.putExtra("bedNum",info.orderDetail.bedNum);
                    startActivity(intent);
                }
            });
            tv_kf.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Intent intentCallPhone = new Intent(Intent.ACTION_DIAL, Uri.parse("tel:" + kfPhone));
                    startActivity(intentCallPhone);
                }
            });
        } else if ("2".equals(status)) {
            tv_state.setText("待收款");
            tv_btn.setText("立即收款");
            tv_btn.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    ewm = HttpAddress.SERVICE_URL+"wap/patient/order/toPay.htm?orderId="+info.orderDetail.orderId;
                    ErweimaDialog(ewm);
                }
            });
            tv_kf.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Intent intentCallPhone = new Intent(Intent.ACTION_DIAL, Uri.parse("tel:" + kfPhone));
                    startActivity(intentCallPhone);
                }
            });
        } else if ("3".equals(status)) {
            tv_state.setText("已付款");
            tv_btn.setText("上传申请单");
            tv_btn.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Intent  intent =  new Intent(OrderDetailsAvtivity.this,RequisitionActivity.class);
                    intent.putExtra("ORDER_ID",info.orderDetail.orderId);
                    startActivity(intent);

                }
            });
            tv_kf.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Intent intentCallPhone = new Intent(Intent.ACTION_DIAL, Uri.parse("tel:" + kfPhone));
                    startActivity(intentCallPhone);
                }
            });
        } else if ("4".equals(status)) {
            tv_state.setText("已送样");
            tv_kf.setVisibility(View.GONE);
            tv_btn.setBackgroundResource(R.drawable.dialog_version_bg_button_qx);
            tv_btn.setText("客服电话");
            tv_btn.setTextColor(Color.parseColor("#212121"));
            tv_btn.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Intent intentCallPhone = new Intent(Intent.ACTION_DIAL, Uri.parse("tel:" + kfPhone));
                    startActivity(intentCallPhone);
                }
            });


        }else if ("5".equals(status)) {
            tv_state.setText("实验室检测中");
            tv_kf.setVisibility(View.GONE);
            tv_btn.setBackgroundResource(R.drawable.dialog_version_bg_button_qx);
            tv_btn.setText("客服电话");
            tv_btn.setTextColor(Color.parseColor("#212121"));
            tv_btn.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Intent intentCallPhone = new Intent(Intent.ACTION_DIAL, Uri.parse("tel:" + kfPhone));
                    startActivity(intentCallPhone);
                }
            });
        }else if ("6".equals(status)) {
            tv_state.setText("已完成");
            tv_kf.setVisibility(View.GONE);
            tv_btn.setBackgroundResource(R.drawable.dialog_version_bg_button_qx);
            tv_btn.setText("客服电话");
            tv_btn.setTextColor(Color.parseColor("#212121"));
            tv_btn.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Intent intentCallPhone = new Intent(Intent.ACTION_DIAL, Uri.parse("tel:" + kfPhone));
                    startActivity(intentCallPhone);
                }
            });
        }else if ("7".equals(status)) {
            tv_state.setText("已退款");
            tv_kf.setVisibility(View.GONE);
            tv_btn.setBackgroundResource(R.drawable.dialog_version_bg_button_qx);
            tv_btn.setText("客服电话");
            tv_btn.setTextColor(Color.parseColor("#212121"));
            tv_btn.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Intent intentCallPhone = new Intent(Intent.ACTION_DIAL, Uri.parse("tel:" + kfPhone));
                    startActivity(intentCallPhone);
                }
            });
        }else if ("8".equals(status)) {
            if (info.orderDetail.cancelReason != null){
                tv_state.setText("已取消"+"("+info.orderDetail.cancelReason+")");
            }else {
                tv_state.setText("已取消");
            }
            tv_kf.setVisibility(View.GONE);
            tv_btn.setBackgroundResource(R.drawable.dialog_version_bg_button_qx);
            tv_btn.setText("客服电话");
            tv_btn.setTextColor(Color.parseColor("#212121"));
            tv_btn.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Intent intentCallPhone = new Intent(Intent.ACTION_DIAL, Uri.parse("tel:" + kfPhone));
                    startActivity(intentCallPhone);
                }
            });
        }
    }


    private void addImgs(final ArrayList<String> list) {
        int windowWidth = SharedPreferencesUtil.getInt(this, "windowWidth");
        int imgWt = (windowWidth - GeneralUtil.dip2px(this, 50)) / 4;
        for (int i = 0; i < list.size(); i++) {
            View view = View.inflate(this, R.layout.item_order_imgs, null);
            ImageView img = ViewHolder.get(view, R.id.iv_order_img);
            ViewGroup.LayoutParams para = img.getLayoutParams();
            para.height = imgWt;
            para.width = imgWt;
            img.setLayoutParams(para);
            GeneralUtil.loadImg(this, list.get(i), img);
            ll_add_ims.addView(view);
            final int finalI = i;
            view.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Intent intent = new Intent(OrderDetailsAvtivity.this, LookImageActivity.class);
                    intent.putStringArrayListExtra("IMGS", list);
                    intent.putExtra("POSITION", finalI);
                    startActivity(intent);
                    overridePendingTransition(R.anim.zoomin, R.anim.zoomout);
                }
            });
        }
    }

    private void addJcxm(List<OrderItemBean> itemList) {
        for (int i = 0; i < itemList.size()+1; i++) {
            View xmView = View.inflate(this, R.layout.item_jcxm, null);
            TextView tv_name = ViewHolder.get(xmView, R.id.tv_order_status_name);
            TextView tv_order_status = ViewHolder.get(xmView, R.id.tv_order_status);
            if (i < itemList.size()){
                tv_name.setText(itemList.get(i).itemName);
                tv_order_status.setTextColor(Color.parseColor("#5F5F5F"));
                //   0：检测中 1：报告已出 2：检测失败
                if ("0".equals(itemList.get(i).itemStatus)){
                    tv_order_status.setText("检测中");
                }else if ("1".equals(itemList.get(i).itemStatus)){
                    tv_order_status.setText("报告已出");
                }else if ("2".equals(itemList.get(i).itemStatus)){
                    tv_order_status.setText("检测失败");
                }
            }else {
                tv_name.setText("订单合计");
                tv_order_status.setTextColor(Color.parseColor("#F54740"));
                tv_order_status.setText("¥  "+info.orderDetail.orderAmount);
            }
            ll_jcxm.addView(xmView);
        }
    }


    @Override
    public void onClick(View view) {
        switch (view.getId()) {


            default:
                break;
        }
    }
    private void ComfirmDialog(){
        comfirmOrderDialog  = new ComfirmOrderDialog(this,"确认接单", R.style.MyDialogStyle, new BaseDialog.LeaveMyDialogListener() {

            @Override
            public void onClick(View view) {
                switch (view.getId()) {
                    case R.id.bt_quit_qx:
                        comfirmOrderDialog.dismiss();
                        break;
                    case R.id.bt_quit_ok:
                        comfirmOrderDialog.dismiss();
                        EditText ed_bz = comfirmOrderDialog.findViewById(R.id.ed_bz);
                        ed_bz.setFilters(new InputFilter[]{emojiFilter,new InputFilter.LengthFilter(50)});
                        String orderNote = ed_bz.getText().toString().trim();
                        if (orderNote.length()>50){
                            ToastUtil.showToast(getApplicationContext(),"字数超过限制(50字内)！");
                            return;
                        }
                        receivePost(orderId,orderNote);
                        break;

                    default:
                        break;
                }
            }
        });
        comfirmOrderDialog.setCanceledOnTouchOutside(false);
        comfirmOrderDialog.show();
    }
    private void ErweimaDialog( String ewm){
        erWeiMaDialog  = new ErWeiMaDialog(this,"收款",ewm, R.style.MyDialogStyle, new BaseDialog.LeaveMyDialogListener() {

            @Override
            public void onClick(View view) {
                switch (view.getId()) {
                    case R.id.iv_close:
                        erWeiMaDialog.dismiss();
                        break;
                    default:
                        break;}
            }
        });
        erWeiMaDialog.setCanceledOnTouchOutside(false);

        erWeiMaDialog.show();
    }

    @Override
    public void onSuccess(String response, int flag) {
        int status = JsonUtil.getInt(response, "status", 0);
        try {
            switch (flag) {
                case 1:
                    OrderDetailDetail(response);
                    break;
                case 2:
                    messageUpdataDetail(response);
                    break;
                case 3:
                    receiveDetail(response);
                    break;
                default:
                    break;
            }
        } catch (Exception e) {
            GeneralUtil.tryShow(getContext(), e);
        }
    }

    private void receiveDetail(String response) {
        int status = JsonUtil.getInt(response, "status", 0);
        String msg = JsonUtil.getString(response,"msg","");
        if (status == 1){
            EventBus.getDefault().post(new OrderListEvent());
            orderDetailPost(orderId);
//            finish();
        }else {
            ToastUtil.showToast(getApplicationContext(),msg);
        }
    }

    private void messageUpdataDetail(String response) {
        int status = JsonUtil.getInt(response, "status", 0);
        if (status == 1){
           EventBus.getDefault().post(new NoticeEvent());
        }else {

        }
    }
    private void OrderDetailDetail(String response) {
        Log.i("lzx", "OrderDetailDetail: " + response);
        int status = JsonUtil.getInt(response, "status", 0);
        String msg = JsonUtil.getString(response,"msg","");
        if (status == 1){
            String data = JsonUtil.getString(response,"data","");
            info = JSON.parseObject(data, ManageOrderDetailInfo.class);
            if (info.orderDetail.appImgArr.size() > 0){
                tv_itemIMG.setVisibility(View.GONE);
                hsv_img.setVisibility(View.VISIBLE);
                list.addAll(info.orderDetail.appImgArr);
                addImgs(list);
            }else {
                tv_itemIMG.setVisibility(View.VISIBLE);
                hsv_img.setVisibility(View.GONE);
            }
            if (info.orderDetail.items.size()>0){
                itemList.addAll(info.orderDetail.items);
                addJcxm(itemList);
            }else {
                ll_jcxm.setVisibility(View.GONE);
                tv_item.setVisibility(View.VISIBLE);
            }
            tvHzName.setText("患者姓名："+info.orderDetail.patientName);
            tvHzBednum.setText("病床号："+info.orderDetail.bedNum);
            if (info.orderDetail.bloodNum ==null){
                tvHzBloodnum.setText("血样编号："+"暂无信息");
            }else {
                tvHzBloodnum.setText("血样编号："+info.orderDetail.bloodNum);
            }
            if (info.orderDetail.patientTel ==null){
                tvHzPhone.setText("患者电话："+"暂无信息");
                iv_patphone.setVisibility(View.GONE);
            }else {
                tvHzPhone.setText("患者电话："+info.orderDetail.patientTel);
                iv_patphone.setVisibility(View.VISIBLE);
            }

            tvHzTime.setText("取样时间："+info.orderDetail.sampling_time);
            if (info.orderDetail.headImg ==null){
                iv_ys_img.setImageResource(R.mipmap.user_icon);
            }else {
                GeneralUtil.loadUserImg(this, info.orderDetail.headImg, iv_ys_img);
            }

            tvYsXinxi.setText( info.orderDetail.doctorRealname+"/"+info.orderDetail.docDepartment +"  "+info.orderDetail.doctorTel);
            tvYsHos.setText(info.orderDetail.hospitalName);
            if (info.orderDetail.logisticRealname ==null){
                tvLogisticXinxi.setText("物流人员："+"暂无信息");
                iv_call.setVisibility(View.GONE);
            }else {
                tvLogisticXinxi.setText("物流人员："+info.orderDetail.logisticRealname+"  "+info.orderDetail.logisticTel);
                iv_call.setVisibility(View.VISIBLE);
            }

            if (info.orderDetail.orderNote ==null){
                tvLogisticBeizhu.setText("物流备注："+"暂无信息");
            }else {
                tvLogisticBeizhu.setText("物流备注："+info.orderDetail.orderNote);
            }
            if (info.orderDetail.receive_time ==null){
                tvLogisticTime.setText("接单时间："+"暂无信息");
            }else {
                tvLogisticTime.setText("接单时间："+info.orderDetail.receive_time);
            }
            if (info.orderDetail.salesmenRealname ==null){
                tvSaleName.setText("销售人员："+"暂无信息");
            }else {
                tvSaleName.setText("销售人员："+info.orderDetail.salesmenRealname);
            }
            if (info.orderDetail.salesmenTel ==null){
                tvSalePhone.setText("销售电话："+"暂无信息");
                iv_salephone.setVisibility(View.GONE);
            }else {
                tvSalePhone.setText("销售电话："+info.orderDetail.salesmenTel);
                iv_salephone.setVisibility(View.VISIBLE);
            }

            if ("1".equals(info.orderDetail.orderType)){
                tvSaleTpye.setText("订单类型：普通订单");
                tvSaleNum.setText("订单编号："+info.orderDetail.orderSn);
                tvSaleRe.setVisibility(View.GONE);
            }else {
                tvSaleTpye.setText("订单类型：加做订单");
                tvSaleNum.setText("订单编号："+info.orderDetail.orderSn);
                tvSaleRe.setText("原订单号："+info.orderDetail.originalOrderSn);
            }
            tvSaleTime.setText("下单时间："+info.orderDetail.create_time);
            intview(info.orderDetail.orderStatus);
            iv_call.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Intent intentCallPhone = new Intent(Intent.ACTION_DIAL, Uri.parse("tel:" + info.orderDetail.logisticTel));
                    startActivity(intentCallPhone);
                }
            });
            iv_patphone.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Intent intentCallPhone = new Intent(Intent.ACTION_DIAL, Uri.parse("tel:" + info.orderDetail.patientTel));
                    startActivity(intentCallPhone);
                }
            });
            iv_salephone.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Intent intentCallPhone = new Intent(Intent.ACTION_DIAL, Uri.parse("tel:" + info.orderDetail.salesmenTel));
                    startActivity(intentCallPhone);
                }
            });
            iv_ys_call.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Intent intentCallPhone = new Intent(Intent.ACTION_DIAL, Uri.parse("tel:" + info.orderDetail.doctorTel));
                    startActivity(intentCallPhone);
                }
            });
            EventBus.getDefault().post(new OrderTabListEvent());
        }else {
            ToastUtil.showToast(getContext(),msg);
        }

    }

    @Override
    public void onFailure(Request request, IOException e, int flag) {

    }
    @Override
    @Subscribe
    public void onEventMainThread(BaseEvent event) throws IOException {
        super.onEventMainThread(event);

        if (event instanceof OrderIdEvent) {
            if (erWeiMaDialog!=null){
                erWeiMaDialog.dismiss();
            }
            orderDetailPost(((OrderIdEvent) event).getOrderId());

        }
    }
    InputFilter emojiFilter = new InputFilter() {
        Pattern emoji = Pattern.compile("[\ud83c\udc00-\ud83c\udfff]|[\ud83d\udc00-\ud83d\udfff]|[\u2600-\u27ff]",
                Pattern.UNICODE_CASE | Pattern.CASE_INSENSITIVE);

        @Override
        public CharSequence filter(CharSequence source, int start, int end, Spanned dest, int dstart, int dend) {
            Matcher emojiMatcher = emoji.matcher(source);
            if (emojiMatcher.find()) {

                return "";
            }
            return null;
        }
    };
}
